/**
 * @(#) ToastUtils 2015/7/6
 *
 *
 * Copyright (c), 2009 深圳孔方兄金融信息服务有限公司（Shenzhen kfxiong
 * Financial Information Service Co. Ltd.）
 *
 *
 * 著作权人保留一切权利，任何使用需经授权。
 */
package com.zztl.infiniteBand.util

import android.content.Context
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import android.widget.Toast
import com.zztl.infiniteBand.R


object ToastUtils {
    fun show(context: Context, promt: String) {

            val toast = Toast.makeText(UiUtils.context, promt, Toast.LENGTH_SHORT)
            toast.setGravity(Gravity.CENTER, 0, 0)
            toast.show()

    }

    fun show(promt: String, hasImg: Boolean, imgId: Int) {
        var toast: Toast?
        if (promt.isNotEmpty()) {
            if (hasImg) {
                val v = LayoutInflater.from(UiUtils.context).inflate(R.layout.img_toast, null)
                val textView = v.findViewById<View>(R.id.tv) as TextView
                val imageView = v.findViewById<View>(R.id.iv) as ImageView
                imageView.setImageResource(imgId)
                textView.text = promt
                toast = Toast(UiUtils.context)
                toast.duration = Toast.LENGTH_SHORT
                toast.view = v
            } else {
                toast = Toast.makeText(UiUtils.context, promt, Toast.LENGTH_SHORT)
            }
            toast?.setGravity(Gravity.CENTER, 0, 0)
            toast?.show()
        }

    }

}
